package com.wzdigit.wms.wms.service.core;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wzdigit.wms.basic.domain.oqc.OqcInsp;
import com.wzdigit.wms.basic.domain.oqc.OqcInspDtl;
import com.wzdigit.wms.basic.mapper.core.oqc.OqcInspDtlMapper;
import com.wzdigit.wms.basic.mapper.core.oqc.OqcInspMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class OqcInspServcie {

    @Autowired
    OqcInspMapper oqcInspMapper;

    @Autowired
    OqcInspDtlMapper oqcInspDtlMapper;

    public OqcInspDtlMapper getOqcInspDtlMapper() {
        return this.oqcInspDtlMapper;
    }

    public OqcInspMapper getOqcInspMapper() {
        return this.oqcInspMapper;
    }

    /**
     * 通过sn列表获取对应的oqc送检信息
     *
     * @param snList
     * @return
     */
    public List<OqcInspDtl> selectDetailListByGoodsSns(List<String> snList) {
        return this.oqcInspDtlMapper.selectByGoodsSNList(snList);
    }

    /**
     * 获取送检单信息
     *
     * @param ids
     * @return
     */
    public List<OqcInsp> selectBatchIds(List<Integer> ids) {
        return this.oqcInspMapper.selectBatchIds(ids);
    }
    
    /**
     * 根据送检单获取未处理的明细的总数
     * @param oqcInspId
     * @return
     */
    public Integer selectTotalNoDealDtlSizeByOqcInspId(Integer oqcInspId) {
    	QueryWrapper<OqcInspDtl> queryWrapper = new QueryWrapper<>();
    	queryWrapper.eq("OQC_INSP_ID", oqcInspId);
    	queryWrapper.eq("STATUS", 0);				// 未处理
        return this.oqcInspDtlMapper.selectCount(queryWrapper);
    }

    /**
     * 根据送检单好获取送检信息
     *
     * @param billno
     * @return
     */
    public OqcInsp selectByInspNo(String billNo) {
        QueryWrapper<OqcInsp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("INSP_NO", billNo);
        List<OqcInsp> list = this.oqcInspMapper.selectList(queryWrapper);
        if (list.size() == 0)
            return null;
        return list.get(0);
    }
}
